// 登录日志服务层

package service

import (
	"admin-go-api/api/dao"
	"admin-go-api/api/entity"
	"admin-go-api/common/result"
	"github.com/gin-gonic/gin"
)

type ISysLoginInfoService interface {
	GetSysLoginInfoList(c *gin.Context, PageSize, PageNum int, Username, LoginStatus, BeginTime, EndTime string)
	BatchDeleteSysLoginInfo(c *gin.Context, dto entity.DelSysLoginInfoDto)
	DeleteSysLoginInfoById(c *gin.Context, dto entity.SysLoginInfoIdDto)
	CleanSysLoginInfo(c *gin.Context)
}

type SysLoginInfoServiceImpl struct {
}

// GetSysLoginInfoList 获取登录日志列表
func (s *SysLoginInfoServiceImpl) GetSysLoginInfoList(c *gin.Context, PageSize, PageNum int,
	Username, LoginStatus, BeginTime, EndTime string) {
	if PageSize <= 0 {
		PageSize = 10
	}
	if PageNum <= 0 {
		PageNum = 1
	}
	sysLoginInfo, count := dao.GetSysLoginInfoList(PageSize, PageNum, Username, LoginStatus, BeginTime, EndTime)
	result.Success(c, map[string]interface{}{"total": count, "pageSize": PageSize, "pageNum": PageNum, "list": sysLoginInfo})
}

// BatchDeleteSysLoginInfo 批量删除登录日志
func (s *SysLoginInfoServiceImpl) BatchDeleteSysLoginInfo(c *gin.Context, dto entity.DelSysLoginInfoDto) {
	dao.BatchDeleteSysLoginInfo(dto)
	result.Success(c, true)
}

// DeleteSysLoginInfoById 根据id删除日志
func (s *SysLoginInfoServiceImpl) DeleteSysLoginInfoById(c *gin.Context, dto entity.SysLoginInfoIdDto) {
	dao.DeleteSysLoginInfoById(dto)
	result.Success(c, true)
}

// CleanSysLoginInfo 清空日志列表
func (s *SysLoginInfoServiceImpl) CleanSysLoginInfo(c *gin.Context) {
	dao.CleanSysLoginInfo()
	result.Success(c, true)
}

var sysLoginInfoService = SysLoginInfoServiceImpl{}

func SysLoginInfoService() ISysLoginInfoService {
	return &sysLoginInfoService
}
